//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "LsmBasisSystem.h"
using namespace Cephei::QL::Methods::Montecarlo;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::CLsmBasisSystem (boost::shared_ptr<QuantLib::LsmBasisSystem>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phLsmBasisSystem = NULL;
#endif
	_ppLsmBasisSystem = &childNative;
    
}
Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::CLsmBasisSystem (QuantLib::LsmBasisSystem& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phLsmBasisSystem = NULL;
#endif
	_ppLsmBasisSystem = new boost::shared_ptr<QuantLib::LsmBasisSystem> (&childNative);
    
    _LsmBasisSystemOwner = owner;
    
}

Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::CLsmBasisSystem (CLsmBasisSystem^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phLsmBasisSystem = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppLsmBasisSystem = new boost::shared_ptr<QuantLib::LsmBasisSystem> (copy->GetShared());
        
    }
}
Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::CLsmBasisSystem (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phLsmBasisSystem = NULL;
#endif
	if (!t->IsSubclassOf(CLsmBasisSystem::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::CLsmBasisSystem (QuantLib::Handle<QuantLib::LsmBasisSystem>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phLsmBasisSystem = &childNative;
	_ppLsmBasisSystem = &static_cast<boost::shared_ptr<QuantLib::LsmBasisSystem>>(childNative.currentLink());
    
    _LsmBasisSystemOwner = owner;
}
Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::CLsmBasisSystem (QuantLib::Handle<QuantLib::LsmBasisSystem> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phLsmBasisSystem = &childNative;
	_ppLsmBasisSystem = &static_cast<boost::shared_ptr<QuantLib::LsmBasisSystem>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::CLsmBasisSystem (QuantLib::LsmBasisSystem childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phLsmBasisSystem = NULL;
#endif
	_ppLsmBasisSystem = new boost::shared_ptr<QuantLib::LsmBasisSystem> (new QuantLib::LsmBasisSystem (childNative));
    
}
#endif

Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::~CLsmBasisSystem ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppLsmBasisSystem != NULL)
    {
	    delete _ppLsmBasisSystem;
        _ppLsmBasisSystem = NULL;
    }
}
Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::!CLsmBasisSystem ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppLsmBasisSystem != NULL)
    {
	    delete _ppLsmBasisSystem;
    }
}
QuantLib::LsmBasisSystem& Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::GetReference ()
{
    if (_ppLsmBasisSystem == NULL) throw gcnew NativeNullException ();
	return **_ppLsmBasisSystem;
}
boost::shared_ptr<QuantLib::LsmBasisSystem>& Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::GetShared ()
{
    if (_ppLsmBasisSystem == NULL) throw gcnew NativeNullException ();
	return *_ppLsmBasisSystem;
}
QuantLib::LsmBasisSystem* Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::GetPointer ()
{
    if (_ppLsmBasisSystem == NULL) throw gcnew NativeNullException ();
	return &**_ppLsmBasisSystem;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::LsmBasisSystem>& Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::GetHandle ()
{
	if (_phLsmBasisSystem == NULL)
	{
		_phLsmBasisSystem = new Handle<QuantLib::LsmBasisSystem> (*_ppLsmBasisSystem);
	}
	return *_phLsmBasisSystem;
}
#endif
bool Cephei::QL::Methods::Montecarlo::CLsmBasisSystem::HasNative () 
{
	return (_ppLsmBasisSystem != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

